import {
  getUserInfo
} from "../../utils/http";
import {
  focusCount
} from "../../api/um";

const globalData = getApp().globalData;
const {
  userInfo,
  config
} = globalData
Page({
  /**
   * 页面的初始数据
   */
  data: {
    config,
    userInfo,
    linkList: [
      [{
          icon: "/images/mine/ico01.png",
          text: "个人资料",
          pageUrl: "/pageA/pages/personal-info/index",
        },
        {
          icon: "/images/mine/ico02.png",
          text: "个人相册",
          pageUrl: "/pageA/pages/personal-photo/index",
        },
        {
          icon: "/images/mine/ico03.png",
          text: "预览主页",
          pageUrl: "/pageA/pages/friends-card/index",
        },
        {
          icon: "/images/mine/ico06.png",
          text: "我的活动",
          pageUrl: "/pageA/pages/activity/index",
        },
        {
          icon: "/images/mine/ico07.png",
          text: "我的积分",
          pageUrl: "/pageA/pages/sign/index",
        },
      ],
      [{
        icon: "/images/mine/ico04.png",
        text: "领证贺礼",
        pageUrl: "/pageA/pages/weddingGift/index",
      }, 
    ],
      [{
          icon: "/images/mine/ico05.png",
          text: "意见反馈",
          pageUrl: "/pageA/pages/feedback/index",
        },
        {
          icon: "/images/mine/ico08.png",
          text: "关于我们",
          pageUrl: "/pageA/pages/about/index",
        },
      ]
    ],
    focusCountMap: {},
    showAuth:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      userInfo: globalData.userInfo
    })
  },
  getFocusCount() {
    focusCount(res => {
      this.setData({
        focusCountMap: res.data
      })
    })
  },
  goFocusList(e) {
    const { type } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pageA/pages/focusList/index?type=${type}`,
    });
  },
  handleLink(e){
    const {item} = e.currentTarget.dataset
    wx.navigateTo({
      url: item.pageUrl,
    });
  },
  // 认证
  handleAuth(e) {
    this.setData({showAuth: true})
  },
  handleCloseAuth(){
      this.setData({showAuth:false})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setSelected(2);
    }
    getUserInfo(() => {
      this.setData({
        userInfo: globalData.userInfo
      })
    })
    this.getFocusCount();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},

});